import 'package:appflutterhomeschool/model/student_information_model.dart';
import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/status_item_widget.dart';
import 'package:appflutterhomeschool/view_model/notice/recipient_list_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/21
///邮箱： 1037438704@qq.com
///功能： 接收人列表
class RecipientListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ProviderWidget<RecipientListViewModel>(
      model: RecipientListViewModel(context),
      onModelReady: (value) => value.initData(),
      builder: (context, viewModel, child) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: MyAppBar2(title: "接收人列表"),
          body: viewModel.studentList.length == 0
              ? Center(
                  child: CircularProgressIndicator(
                      backgroundColor: Colors.blueAccent))
              : Stack(
                  children: <Widget>[
                    Positioned(
                      top: 0,
                      left: 0,
                      right: 0,
                      bottom: ScreenUtil().setWidth(115),
                      child: SingleChildScrollView(
                        child: Column(
                          children: <Widget>[
                            Container(
                              child: ListTile(
                                title: Text("全选",
                                    style: TextStyles.textDark37,
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis),
                                trailing: Icon(
                                    viewModel.selectAll
                                        ? Icons.brightness_1
                                        : Icons.panorama_fish_eye,
                                    color: viewModel.selectAll
                                        ? Colors.blue
                                        : Colors.grey,
                                    size: ScreenUtil().setWidth(38)),
                                onTap: viewModel.selectAllOnTap,
                              ),
                              decoration: BoxDecoration(
                                  border: Border(
                                      bottom: BorderSide(
                                          width: 10, color: Colors.grey[100]))),
                            ),
                            ListView.builder(
                                physics: NeverScrollableScrollPhysics(),
                                shrinkWrap: true,
                                itemCount: viewModel.studentList.length,
                                itemBuilder: (context, index) {
                                  return StatusItemWidget(
                                    imageUrl: viewModel.studentList[index].img,
                                    title: viewModel.studentList[index].name,
                                    onTap: () => viewModel.studentOnTap(index),
                                    rightWidget: Icon(
                                        !viewModel.studentList[index].choice
                                            ? Icons.panorama_fish_eye
                                            : Icons.brightness_1,
                                        color:
                                            viewModel.studentList[index].choice
                                                ? Colors.blueAccent
                                                : Colors.grey,
                                        size: ScreenUtil().setWidth(38)),
                                  );
                                }),
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                        bottom: 0,
                        left: 0,
                        right: 0,
                        child: Container(
                          color: Colors.white,
                          child: ButtonWidget().rectangleButtonWidget(
                              buttonName: "确定",
                              onPressed: () {
//                                viewModel.studentList[index].choice
                                List<StudentModel> list = [];
                                viewModel.studentList.forEach((element) {
                                  if (element.choice) {
                                    list.add(element);
                                  }
                                });

                                Navigator.pop(context, {"list": list});
                              }),
                        ))
                  ],
                ),
        );
      },
    );
  }
}
